﻿using INTEX.SCHEDULER;
using ReflectionStudio.Core.Events;
using System.ComponentModel;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for EditEventWindow.xaml
    /// </summary>
    public partial class TSAV33
    { 

        public TSAV33()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VICC_MKRF(); 
            DataContext = MV; 
            IsAV = true;
            zAV33Height = 400;
            MESSAGES += "SSHOWGANT;";
            InitializeComponent();
            TMV.Scheduler = new SPAPS();
            TMV.SetUpAV33();
            if (app.User == "ITXV    ")
            {
             //   LFD = "026058";
            }
        }

        
        public override void OnWorkflowIDChange(MessageEventArgs e)
        {
            MessageInfo msg = e.Info;
            string task = msg.MSGTYPE;
            switch (task)
            {
                case "SSHOWGANT":
                    if (zAV33Height >= 500)
                        zAV33Height = 400;
                    break;
            }
        } 
       
        private void ReSetTab()
        {
            IsAV = false; 
        }

    
        TAVAFKS cAV;
        bool IsLoadMK = false;

        public override void QueryCommand(object sender, RoutedEventArgs e)
        {
            IsLoadMK = true;
            NormalTask = System.Threading.Tasks.Task.Factory.StartNew(() => LoadMKRF(), new CancellationTokenSource().Token, TaskCreationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
            base.QueryCommand(sender, e);
        }
        private void LoadMKRF()
        {
            TMV.VKK.UVKK04(null);
            dwData = TBMain.NewRow();
            dwData["ABFMANDANT"] = app.Mandant;
            dwData["ABFKSTKRS"] = KSTKRS;
            dwData["ABFKST"] = KST;
            dwData["ABFAGANG"] = AGANG;
            dwData["MKFERLKZ"] = " ";
            SResult = TMV.QTMKRF03(dwData);
            TMV.MergeData(SResult, true, true);
        }

        private void StartScheduleCommand(object sender, RoutedEventArgs e)
        {
            NormalTask = System.Threading.Tasks.Task.Factory.StartNew(() => StartScheduleCommand(), new CancellationTokenSource().Token, TaskCreationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
        }
        public void StartScheduleCommand()
        {
            TMV.VKK.UVKK04(null);
            if (FTAUTOSPLIT)
            {
                if (cAV == null)
                {
                    cAV = new TAVAFKS();
                    cAV.KSTKRS = KSTKRS;
                    cAV.KST = KST;
                    cAV.AGANG = AGANG;
                    cAV.AMTYP = AMTYP;
                }
                cAV.StartReSplit();//先处理已经生产的任务
            }
            PM["KSTKRS"] = KSTKRS;
            PM["KST"] = KST;
            PM["AMTYP"] = AMTYP;
            PM["LFD"] = LFD;
            PM["AGANG"] = AGANG;
            TMV.XSSchedule(PM);
        }

        private void ShowDetailCommand(object sender, RoutedEventArgs e)
        {
            TMV.ShowDetail(dwMKRF);
        }

        private void RefreshCommand(object sender, RoutedEventArgs e)
        {

        }
          
    }
}
